<?
//general page attributes
include('scripts/ad.php');

$categories = services::browse_types();
$categories = $categories['data']; //movies, ios, xbox,...

$user = "N";
if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'google') !== FALSE)
	$user = "G"; //Google Crawler

$url_title = $title;
switch($operation)
{
    case "r":
        $page_title = util::make_title($title.' '.$keywords);
		$title = util::make_title($title);
        break;
    case "b":
        if($content_type)
        {
            $page_title = util::make_title('Browsing '.$content_type.', Page '.$page);
            $browse_title = util::make_title('Browse Top, Latest, and Best '.$content_type.' Content, Page '.$page);
        }
        else
            $page_title = "UDNFind Home";
        break;
}

$page_description = $page_title;
$page_keywords = str_replace('-', ', ', $title.'-'.$keywords);
$keywords = urldecode($keywords);
if($operation=='b')
{
    /* BROWSE */
    $p = $results['page'];
    $letter = $results['letter'];
    $from = $results['from'];
    $to = $results['to'];
    $pages = $results['pages'];
    $size = $results['size'];
    $total = $results['total'];
    $data = $results['data'];

    $np = $p+1;
    $next_url = $folder_url."b/$content_type/$np/$keywords"; //nextpage
    if($letter)
    {
        $letter = strtolower($letter);
        $next_url = $folder_url."b/$content_type/$np-$letter/$keywords"; //nextpage
    }
}
else
{
    /* READ */
    /* add your custom data here using scripts */
    $data['primative'] = primative::get_primative_data($data['sitemap_meta_id'], $data['udnurl'], $data['sourceurl'], $content_type);
	//$data['primative'] = strip_tags($data['primative'], '<ul><li><b><p><div><h1><h2><span>');
	$data['primative'] = preg_replace('/<\/?a[^>]*>/', '', $data['primative']);
    //$data['links'] = scripts::get_generic_keywords_links($folder_url, $udnurl, $title, $keywords);
    //$data['description'] = scripts::get_generic_description($content_type, $title);
    //$data['bing'] = scripts::get_generic_content($folder_url, $content_type, $title, $udnurl);
    if($data['sourceurl'] == null)
    {

        $data['similar'] = scripts::get_generic_similar_links($folder_url, $content_type);

        $data['images'] = scripts::get_generic_images($title);
        $data['poster'] = scripts::get_generic_poster($title, $content_type);

    }
}

//include('forms/header.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title><?=$operation == 'r'? $page_title : $browse_title?></title>
	<meta name="description" content="<?=$page_description?>, <?=substr(strip_tags($data['primative']), 0, 150)?>" />
    <meta name="keywords" content="<?=$page_keywords?>" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <!--analytics-->
    <?= ad::get_analytics() ?>

    <!--jquery-->
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.min.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
    <script type="text/javascript" src="<?=$folder_url?>js/jquery.tablesorter.min.js" ></script>


    <!--re-order-->
    <script type="text/javascript">
        $(function() {
	<?if($operation=='r') {?>
			//reorder content
            $('#zone_a').append($('*[zone="a"]'));
            $('#zone_b').append($('*[zone="b"]'));
			$('#zone_c').append($('*[zone="c"]'));
			$('#zone_d').append($('*[zone="d"]'));
			
			//hide short description
			$('p[itemprop="description"]').hide();


            //selected Category
            //$('li[code="<?=strtolower($content_type)?>"]').addClass("current_page_item");
    <?}?>

	
	<?if($operation=='r') {?>
			<!--run Scripts-->
			searchYoutube("<?=$title.'-'.$data['youtube']?>", "youtube");
			download("http://udnfind.com", "<?=$title?>", "<?=$data['filestube']?>", 'download-tabs');
	<?}?>
	<?if($operation=='b' && $keywords) {?>
			<!--run Scripts-->
			searchYoutube("<?=$keywords?>", "youtube");

            <?if($content_type != "all") {?>
			download("http://udnfind.com", "<?=$keywords?>", "@<?=$content_type?>@", 'download-tabs');
            <?}
            else {?>
            download("http://udnfind.com", "<?=$keywords?>", "@@", 'download-tabs');
            <?}?>
	<?}?>		
        });
    </script>

    <!-- TODO: Movie this style into standalone css -->
    <style type="text/css">
        body {font-family: Verdana, sans-serif; color: #5b5b5b; font-size: 13px; width: 1020px; margin: 0 auto;}
        a {text-decoration: none; margin:5px 5px; color: #0055bb; font-weight:bold;}
		a:visited {color: #0055bb;}
        a:hover {color: blue;}
        h1 {margin-top: 0; font-family: "Trebuchet MS", sans-serif;}
        h2 {font-size: 16px;}
        select, option { height: 30px;}
        @-moz-document url-prefix() {
            select, option { height: 30px; padding:6px;}
        }
        button { height:30px; width: 50px;}

        #udn_navigation {width: 100%; text-align:center; /*background-color: #fbfbfb;*/}
        #udn_navigation ul {list-style: none; padding: 0; margin: 0;  }
        #udn_navigation ul li{ margin: 0; padding:0; display: inline-block; border-right:solid 1px silver;}
        #udn_navigation ul li:last-child { margin: 0; padding:0; display: inline-block; border:none;}
        #udn_navigation ul li a{padding:12px 12px; margin: 0; text-decoration: none; display: inline-block;}
        #udn_navigation ul li a:hover{text-decoration: none; background-color: #0078ae; color: white;}
        li.active a{background-color: orange; color: white;}

        #udn_search { margin-top: 20px; padding: 10px; height: 40px; /*background-color: #fbfbfb;*/}
        #udn_search span { text-align: center; font-size:22px; font-weight:bold; float:left; width: 250px;}
        #udn_search form {  }
        #udn_search form input { height: 24px; }
        #udn_search form input[type="text"]:focus { border: solid 1px #0000ff; }


        #udn_content {padding: 0px;}

            /* left panel */
        #udn_left {float: left; width: 200px; padding:0 20px; /* background-color: #fbfbfb;*/}
        /*#udn_left #udn_poster {width: 200px; height: 260px; margin-bottom: 20px; }*/
		#udn_left .udn_poster img {width: 200px; margin-bottom: 20px; }
        #udn_left #udn_ad_box {width: 180px; height: 150px; margin-left: 10px; }
        #udn_left #udn_available ul{list-style: none; padding: 0; margin: 0;}
        #udn_left #udn_available ul li {margin: 5px 0;}

            /* right panel */
        #udn_right {float: left; width: 730px; padding:0 20px; border-left: solid 1px silver;}
        #udn_right #udn_ad_banner {width: 728px; height: 90px; }
		#udn_right #udn_links li { width: 300px; display:inline-block;}
		.ui-tab-content, .ui-tabs-panel{overflow: auto; height: 300px; font-size:12px;}
		.ui-tabs-panel tr:nth-child(even) {background-color: #fafafa; }
		
		#udn_left_search {float: left; width: 230px; padding:0 20px; /* background-color: #fbfbfb;*/}
		#udn_left_search ol { padding:0; margin:0; }
		#udn_left_search ol li { padding:0;margin-bottom:10px; }
        #udn_right_search {float: left; width: 700px; padding:0 20px; border-left: solid 1px silver;}

        #udn_browse ol li { margin-bottom:10px; }

        #download-tabs tr:hover { background-color: #FFFBCC;}
        #download-tabs td { padding: 10px;}

    </style>
</head>
<body>
<div id="udn_navigation">
    <ul>
        <li><a href="<?=$folder_url?>b" accesskey="1" title="Homepage">Home</a></li><?foreach($categories as $d){?><li class="<?= ($content_type == strtolower($d['title'])) ? "active" : "" ?>"><a href="<?echo $folder_url.$d['udnurl']?>" title="<?echo $d['title']?>"><?echo $d['title']?></a></li><?}?>
    </ul>
</div>
<div id="udn_search">
    <span><img src="<?=$folder_url?>img/udnfind.png" /></span>
    <form action="<?=$folder_url?>b/<?=$content_type ? $content_type : "all" ?>/1" method="post">
        <input type="text" size="60" name="search" value="<?= $operation == 'b' && $keywords ? str_replace("-"," ", $keywords) : "" ?>" />
        <select name="type">
            <option <?=$content_type == 'all' ? 'selected' : ''?>>all</option>
            <?foreach($categories as $c) {?><option value="<?=strtolower($c['title'])?>" <?=$content_type == strtolower($c['title']) ? 'selected' : ''?>><?=$c['title']?></option><?}?>
        </select>
        <script type="text/javascript">
            $(function(){
                $('form select').change(function(){
                    $('form').attr('action', '<?=$folder_url."b/"?>' + $(this).val().toLowerCase() + '/1');
                });
            });
        </script>
        <button type="submit">Go</button>
    </form>
</div>
<div itemscope itemtype="http://schema.org/CreativeWork" id="udn_content">
    <?if($operation=='r') {?>
    <div id="udn_left">
        <div itemprop="image" id="zone_c" class="udn_poster">
			<!--img id="udn_poster" itemprop="image" src="" alt="<?=$title?>" /-->
		</div>
		
        <div id="udn_ad_box">
            <a  href="http://www.webtrackerplus.com/?a_aid=51a4de24b6608&amp;a_bid=99507c09" target="_blank"><img src="<?=$folder_url?>img/stream.jpg" alt="" title="" width="200px" /></a>
            <!--script type="text/javascript" src="http://clkrev.com/adServe/banners?tid=UDNWEB_2004_0&size=180x150" ></script-->
        </div>
		
		<div id="zone_d">
		</div>

		<?if($user == "N") {?>
        <div id="udn_available">
            <h2>Also Available in</h2>
            <ul>
                <?foreach($categories as $d){?>
                <li code="<?echo strtolower($d['title'])?>"><a href="<?echo $folder_url.$d['udnurl'].'/'.$url_title?>" title="find <?=$title?> in <?echo $d['title']?>"><?echo $d['title']?></a>(...)</li>
                <?}?>
            </ul>
        </div>
		<?}?>
    </div>
    <div id="udn_right">
        <h1 itemprop="alternativeHeadline"><?=$page_title?></h1>
        <div id="udn_ad_banner">
            <a href="http://www.webtrackerplus.com/?a_aid=51a4de24b6608&amp;a_bid=99507c09" target="_blank"><img src="http://trendx.info/res/img/mymoviepass_728x90anim.gif" alt="" title="" width="728" height="90" /></a>
        </div>
        <h2 itemprop="name"><?=$title?></h2>
        <p itemprop="description"><?=$page_description?>, <?=substr(strip_tags($data['primative']), 0, 200)?>, <em><?=$page_description?></em></p>

        <?=$data['description']?>

        <div itemprop="review">
		    <?=$data['primative']?>
        </div>
        <?=$data['bing']?>
		<div id="zone_a">
		</div>
		<?if($data['links']) {?>
		<?echo $title?> is available:
		<?foreach($data['links'] as $link) {?>
			<em><?echo $link['title']?></em>,
		<?}}?>
        <!--p class="button-style"><a href="<?=$data['sourceurl']?>">More Details</a></p-->
        <h2><?=$title?> Videos</h2>
        <div id="udn_video">
            <script type="text/javascript" src="<?=$folder_url?>js/youtube.js"></script>
            <div id="youtube"></div>
        </div>
        <h2><?=$title?> Download</h2>
        <a href="http://www.webtrackerplus.com/?a_aid=51a4de24b6608&amp;a_bid=99507c09" target="_blank"><img src="http://affiliate-robot.com/accounts/default1/banners/v7.gif" alt="" title="" width="728" height="90" /></a>

        <div id="udn_download">
            <script type="text/javascript" src="<?=$folder_url?>js/download.js"></script>
            <div id="download-tabs"></div>
        </div>

        <h2><?=$title?> Pictures</h2>
        <div id="udn_images">
            <div style='overflow-x:scroll;overflow-y:hidden;width:600px'>
                <div id="zone_b" style='width:2500px'></div>
            </div>
        </div>

        <h2><?=$title?> Similar Content</h2>
        <div id="udn_similar">

        </div>
        <h2><?=$title?> Discussion and Comments</h2>
        <div itemprop="comment" itemtype="http://schema.org/UserComments" id="udn_comments">

        </div>
		<h2>Similar Links</h2>
		<div id="udn_links">
            <ul>
                <?if($data['links'])
					foreach($data['links'] as $link) {?>
                <li><a href="<?=$link['url']?>"><strong><?=$link['title']?></strong></a></li>
                <?}?>
            </ul>
        </div>
    </div>
    <?}?>
    <?if($operation=='b') {?>
    <div id="<?= $keywords ? "udn_left_search" : "udn_browse"?>">
        <h2><?=$page_title?></h2>
		<!-- Your Custom functions content -->
        <?
        if($p && !$keywords)
        {
            $letters = array("0~9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","W","V","X","Y","Z");

            ?>

            <?foreach($letters as $l) {
            $letter_url = $folder_url."b/$content_type/1-$l"; //nextpage
            ?>
            <a href="<?=$letter_url?>"><?=$l?></a>
            <?}?>
            <br/>
            <p align="right"><a href='<?= $next_url?>' title="Next Page">Next Page</a></p>


            <?
        }
        ?>
        <ol>
            <?foreach($data as $d){?>
            <li><a href="<?echo $folder_url.$d['udnurl']?>" title="<?echo $d['title']?>"><?echo $d['title']?></a></li>
            <?}?>
        </ol>
        <!-- TODO: Add pagination -->
        <?
        if($p && !$keywords)
        {
            echo "showing results from $from to $to ($size) items, page $p of $pages, total $total items.<br/>";
            $letters = array("0~9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","W","V","X","Y","Z");

            ?>

            <?foreach($letters as $l) {
                $letter_url = $folder_url."b/$content_type/1-$l"; //nextpage
            ?>
            <a href="<?=$letter_url?>"><?=$l?></a>
            <?}?>
            <br/>
            <p align="right"><a href='<?= $next_url?>' title="Next Page">Next Page</a></p>

            <?
        }
        ?>
    </div>
	<?if ($keywords){?>
	<div id="udn_right_search">
	    <h2><?=$keywords?> Videos</h2>
        <div id="udn_video">
            <script type="text/javascript" src="<?=$folder_url?>js/youtube.js"></script>
            <div id="youtube"></div>
        </div>
		<h2><?=$keywords?> Download</h2>
        <div id="udn_download">
            <script type="text/javascript" src="<?=$folder_url?>js/download.js"></script>
            <div id="download-tabs"></div>
        </div>
	</div>
	<?}?>
    <?}?>
    <div style="text-align: right">
        <a href="mailto:udnweb@gmail.com">Report Abuse / Copyright</a>
    </div>
</div>

</body>
</html>
